package h0705;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
  * @description api集群负载统计，优化版本
  * @author 不知名帅哥
  * @date 2024/7/5 23:38
  * @version 1.0
*/
public class APIClusterLoadStatistics2 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //有多少层
        int n= sc.nextInt();
        sc.nextLine();
        //记录各层级字符串出现的频次，下标为层级，记得层级为下标+1
        ArrayList<Map<String, Integer>> maps = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            //读取每一行字符串
            String s = sc.nextLine();
            String[] split = s.substring(1).split("/");
            for (int level=0;level< split.length;level++){
                String str=split[level];
                if (maps.size()<=level){
                    //新建层级。
                    maps.add(new HashMap<>());
                }
                Map<String, Integer> stringMap = maps.get(level);
                stringMap.put(str, stringMap.getOrDefault(str,0)+1);
            }
        }
        //要查找哪一层级
        Integer le = sc.nextInt();
        //要找哪个字符串
        String s = sc.next();
        Map<String, Integer> res = maps.get(le - 1);
        if (le>n){
            System.out.println(0);
        }else {
            System.out.println(res.getOrDefault(s,0));
        }
    }
}
